<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$item=pdo_get('jy_weishop_coupon_sendticket_share',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
	if($item['couponid']){
		$item['couponid']= explode(';', $item['couponid']);
		$cid=$item['couponid'];
		$item['couponid']= substr(implode(',', $item['couponid']),1,strlen(implode(',', $item['couponid']))-2);
		$where = 'and id in(' . $item['couponid'] . ')';
	}

	foreach($cid as $v){
		$backtype=pdo_getcolumn('jy_weishop_coupon',array('id'=>$v),'backtype');
		$data=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'couponid'=>$v,'gettype'=>1,'createtime'=>time(),'backtype'=>$backtype);
		pdo_insert('jy_weishop_coupon_getlog',$data);
	}
	$total = pdo_fetch('select count(*) as total from ' . tablename('jy_weishop_coupon') . ' where uniacid=:uniacid ' . $where, array(':uniacid' => $_SESSION['uniacid']), 'id');
	
	$list = pdo_fetchall('select * from ' . tablename('jy_weishop_coupon') . ' where uniacid=:uniacid ' . $where, array(':uniacid' => $_SESSION['uniacid']), 'id');
	foreach($list as &$v){
		$v['limittimes']=json_decode($v['limittimes'],true);
		$v['limittimes']['tstart']=date('Y/m/d H:m:s',$v['limittimes']['tstart']);
		$v['limittimes']['tend']=date('Y/m/d H:m:s',$v['limittimes']['tend']);
		$v['time']=$v['limittimes']['tstart'].'至'.$v['limittimes']['tend'];
	}
	$return['total']=$total['total'];
	$return['list']=$list;
	exi($return);
}

?>